﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using FriendlyFireLibrary;

namespace NetworkSendTest
{
    public partial class Client2 : Form
    {
        public Client2()
        {
            InitializeComponent();
        }
        NetworkAsyncCodeClient client;
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void MyFunc(byte[] data, int type)
        {
            if (type == 0)
            {
                string h = Encoding.ASCII.GetString(data);
                txtMessage.Text = "Data : " + h + " Type : " + type;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            
            client = new NetworkAsyncCodeClient(textBox2.Text, new NetworkCodeCommon.DataReceived(MyFunc) , textBox1, pbUpload, txtClientName.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            client.Shutdown();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            client.SendMessage(txtMessage.Text);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            client.SendFile(openFileDialog1.FileName);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            client.RequestFile(txtRequestFile.Text);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
            client.SetDir(folderBrowserDialog2.SelectedPath);
        }
    }
}
